﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using RibbonEditor.AppCode;

namespace RibbonEditor.LocLabels
{
    public class LocLabel : IXmlBuildable
    {
        XmlNode locLabelXmlNode;

        public string Id { get; set; }
        public Titles Titles { get; set; }

        public LocLabel() {
            this.Titles = new Titles();
        }

        public LocLabel(XmlNode node)
        {
            try
            {
                this.locLabelXmlNode = node;

                this.Id = (string)XmlHelper.ExtractXmlAttributeToProperty2(node, "Id", XmlHelper.PropertyType.stringType);

                this.Titles = new Titles(node.SelectSingleNode("Titles"));
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public void AddNode(XmlNode locLabelsNode)
        {
            try
            {
                XmlNode locLabelNode = XmlHelper.AddNode(locLabelsNode, "LocLabel");
                XmlHelper.AddAttribute(locLabelNode, "Id", this.Id);
                this.Titles.AddNode(locLabelNode);
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        internal void BuildTreeViewElement(TreeNode parentNode)
        {
            try
            {
                TreeNode node = new TreeNode("LocLabel");
                node.ContextMenuStrip = ContextMenuStripHelper.BuildStandardContextMenuStrip(node);
                node.Tag = this;
                parentNode.Nodes.Add(node);

                node.Expand();

                this.Titles.BuildTreeViewElement(node);
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}